package tools.cyan.com.myapplication.app;

import android.app.Application;
import android.text.TextUtils;

import com.cyan.tools.util.SPUtils;

import tools.cyan.com.myapplication.dagger.TestComponent;

/**
 * Created by pc on 2018/4/25.
 */

public class App extends Application{
    public static App mInstance;
    public static TestComponent testComponent;
    private String token;
    @Override
    public void onCreate() {
        super.onCreate();
        testComponent=TestComponent.TestInitialize.init();
        mInstance=this;
    }
    public static App getApp() {
        if (mInstance != null && mInstance instanceof App) {

            return  mInstance;
        } else {
            mInstance = new App();
            mInstance.onCreate();
            return  mInstance;
        }
    }
    public String getToken() {
        if (TextUtils.isEmpty(token)) token = (String) SPUtils.get(this, "Authorization", "");
        return token;
    }

    public void setToken(String token) {
        SPUtils.put(this, "Authorization", TextUtils.isEmpty(token)?token:"bearer" + token);
        this.token =  TextUtils.isEmpty(token)?token:"bearer" + token;
    }

    public static TestComponent getComponent() {
        return testComponent;
    }
}
